<?php

namespace App\Models\VoteGroup;

use App\Models\VoteGroup\VoteGroup;

class VoteGroupRepository implements \App\Contracts\Repositories\VoteGroup\VoteGroupRepository
{
    public function getMaps($activityId)
    {
        $categories = VoteGroup::where('activity_id', $activityId)
            ->orderBy('order_id', 'ASC')
            ->get(['id', 'title'])->toArray();

        //return array_column($categories, 'title', 'id');
        $maps = [];
        foreach ($categories as $category) {
            $maps[] = [
                'id' => array_get($category, 'id'),
                'title' => array_get($category, 'title'),
            ];
        }

        return $maps;
    }
    /**
     * @param $data
     * @return mixed
     */
    public function create($data)
    {
        $res = VoteGroup::create($data)->id;

        return $res;
    }

    /**
     * @param $id
     * @return mixed
     */
    public function findById($id)
    {
        $res = VoteGroup::find($id);

        return $res;
    }



    /**
     * @param $activityId
     * @return mixed
     */
    public function findByActivityId($activityId)
    {
        $res = VoteGroup::where(['activity_id' => $activityId])
            ->orderBy('order_id', 'ASC')
            ->get();

        return $res;
    }

    /**
     * @param $conditions
     * @return mixed
     */
    public function where($conditions)
    {
        return VoteGroup::where($conditions)->get();
    }


    /**
     * @param $conditions
     * @return mixed
     */
    public function delete($conditions)
    {
        return VoteGroup::where($conditions)->delete();
    }

    /**
     * @param $updates
     * @param $conditions
     * @return mixed
     */
    public function update($updates, $conditions)
    {
        return VoteGroup::query()->where($conditions)->update($updates);
    }
}
